package adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.boltshow.R;

import org.xutils.x;

import java.util.List;

import model.HotMonkeyModel;
import model.HotTitleModel;

/**
 * Created by Administrator on 2016/8/29.
 */
public class HotRVAdapter extends RecyclerView.Adapter<HotRVAdapter.HotViewHolder> {

    private List<HotMonkeyModel> mData;
    private Context mContext;
    private View.OnClickListener mListener;
    public HotRVAdapter(List<HotMonkeyModel> mData, Context mContext, View.OnClickListener listener){
        this.mData = mData;
        this.mContext = mContext;
        mListener = listener;
    }

    @Override
    public HotViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.hot_rv_cardview,null);
        HotViewHolder hotViewHolder = new HotViewHolder(view);
        return hotViewHolder;
    }

    @Override
    public void onBindViewHolder(HotViewHolder holder, int position) {
        HotMonkeyModel hotMonkeyModel = mData.get(position);
        x.image().bind(holder.iv_show,hotMonkeyModel.getTopImg());
        holder.iv_show.setTag(position);
        holder.iv_show.setOnClickListener(mListener);
        holder.tv_title.setText(hotMonkeyModel.getTitle());
        holder.tv_date.setText(hotMonkeyModel.getFlashLabel());
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    static class HotViewHolder extends RecyclerView.ViewHolder {

        private ImageView iv_show;
        private TextView tv_title,tv_date;

        public HotViewHolder(View itemView) {
            super(itemView);
            iv_show = (ImageView) itemView.findViewById(R.id.iv_hot_rv_show);
            tv_title = (TextView) itemView.findViewById(R.id.tv_hot_rv_title);
            tv_date = (TextView) itemView.findViewById(R.id.tv_hot_rv_date);

        }
    }
}
